﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using IHISCETeim.Library;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using IHISCETeim.Model;
using System.Data.SqlClient;

namespace IHISCETeim.DAL
{
    public class FXAgentYuQiDAL
    {
        public static string Add(FXAgentYuQiInfo obj)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FXAgentYuQi_Add", obj.ExpiryType, obj.YearTag,obj.CardName,obj.AliasName,obj.Jan,obj.Feb,obj.Mar,obj.Apr,obj.May,obj.Jun,obj.Jul,obj.Aug,obj.Sep,obj.Oct,obj.Nov,obj.Dec,obj.OpRealName);
            return DB.ExecuteScalar(dbCommand).ToString();


            //SqlParameter LOrderDate = new SqlParameter("@Dec", SqlDbType.Decimal);
            //LOrderDate.IsNullable = true;
            //if (obj.Dec == null)
            //    LOrderDate.Value = DBNull.Value;
            //else
            //    LOrderDate.Value = obj.LOrderDate;
            //dbCommand.Parameters.Add(LOrderDate);

        }
        /// <summary>
        /// 导入操作前行删除之前所有的记录,
        ///需区分导入的类别及年份
        /// </summary>
        /// <param name="ExpiryType"></param>
        /// <param name="YearTag"></param>
        /// <returns></returns>
        public static bool Delete(short YearTag)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FXAgentYuQi_Delete", YearTag);
            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch
            {
                return false;
            }
        }
        /// <summary>
        /// 获取明细
	    ///如果@YearTag为0 则表示获取 ExpiryType　为年度汇总的数据，报表使用
        /// </summary>
        /// <param name="ExpiryType"></param>
        /// <param name="YearTag"></param>
        /// <returns></returns>
        public static DataTable GetList(string ExpiryType, short YearTag)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FXAgentYuQi_GetList", ExpiryType, YearTag);
            return DB.ExecuteDataSet(dbCommand).Tables[0];
        }
        /// <summary>
        /// 获取有在合作的　放款总台数前　　几名的逾期明细
        /// </summary>
        /// <param name="AliasName">代理商简称</param>
        /// <returns></returns>
        public static DataTable ReportGetDetail(string AliasName)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("FXAgentYuQi_ReportGetDetail", AliasName);
            return DB.ExecuteDataSet(dbCommand).Tables[0];
        }
    }
}
